package com.zx.account.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zx.account.dao.UserMapper;
import com.zx.account.entity.User;
import com.zx.account.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getById(int id) {
        log.info("查询User, id={}", id);
        if (id == 0) {
            return null;
        }
        User user = this.userMapper.selectById(id);
        return user;
    }

    @Override
    public User login(String name, String password) {
        log.info("查询User, name={}, password={}", name, password);
        if (password == null || password == null) {
            return null;
        }
        User user = this.userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getName, name));
        // 校验密码
        if (user != null && user.getPassword().equals(password)) {
            return user;
        }
        return null;
    }

}
